package com.jcj.endecoder;

/**
 * 通用工具类
 */
public class CommonTools {

    public static final int FIXEDLENGTHFRAME_LENGTH = 256;//定长解码器FixedLengthFrameDecoder对应的消息长度(字节)

    public static final int LINEBASEDFRAME_LENGTH = 64;//行解码器LineBasedFrameDecoder对应的消息长度

    public static final int DELIMITERBASEDFRAME_LENGTH=64;//分隔符解码器DelimiterBasedFrameDecoder对应的消息长度


    /**
     * 生成指定长度字符串,不足位右补空格,否则返回原字符串(warning:发中文的话计算有问题)
     */
    public static String formatString(String str, int assignlength) {
        int intStrLen = 0;
        if (str != null) {
            intStrLen = str.length();
        }

        System.out.println("字符串的长度:" + intStrLen);

        if (intStrLen >= assignlength) { //如果指定长度和字符串长度一致,直接返回原字符串
            return str;
        } else { //右补空格
            String strSpace = "";
            for (int i = 0, num = assignlength - intStrLen; i < num; i++) {
                strSpace = strSpace + " ";
            }

            return str + strSpace;
        }

    }

}





































